package com.hl.yyx.common.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel(value = "分页数据")
public class ApiData<T> {

    /**
     * 数据
     */
    @ApiModelProperty(value = "数据")
    private List<T> data = new ArrayList<>();

    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总记录数")
    private Long totalRecords = 0L;

    public ApiData() {
    }

    public ApiData(List<T> aaData) {
        this.data = aaData;
    }


    public ApiData(Page<T> page) {
        this.data = page.getRecords();
        if (this.data != null) {
            this.totalRecords = page.getTotal();
        }
    }
    public ApiData(List<T> data, Long totalRecords) {
        this.data = data;
        this.totalRecords = totalRecords;
    }
}
